package com.example.bookapp.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;

import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RadioGroup;

import com.example.clothingapp.R;
import com.example.clothingapp.fragments.HomeFragment;
import com.example.clothingapp.fragments.MineFragment;
import com.example.clothingapp.fragments.RecommendFragment;
import com.example.clothingapp.fragments.TrolleyFragment;

public class HomeActivity extends AppCompatActivity {

    RadioGroup mRGNavi;
    private FragmentManager HomeFragmentManager;
    private FragmentManager RecommendFragmentManager;
    private FragmentManager TrolleyFragmentManager;
    private FragmentManager MineFragmentManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //隐藏顶部状态栏
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_home);

        initView();
        initEvent();
    }

    private void initEvent() {
        mRGNavi.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rdbtn_home:
                        HomeFragmentManager = getSupportFragmentManager();
                        HomeFragmentManager.beginTransaction()
                                .replace(R.id.fl_contaciner,new HomeFragment())
                                .commit();
                        break;
                    case R.id.rabtn_sort:
                        RecommendFragmentManager = getSupportFragmentManager();
                        RecommendFragmentManager.beginTransaction()
                                .replace(R.id.fl_contaciner,new RecommendFragment())
                                .commit();
                        break;
                    case R.id.rdbtn_trolley:
                        TrolleyFragmentManager = getSupportFragmentManager();
                        TrolleyFragmentManager.beginTransaction()
                                .replace(R.id.fl_contaciner,new TrolleyFragment())
                                .commit();
                        break;
                    case R.id.rdbtn_mine:
                        MineFragmentManager = getSupportFragmentManager();
                        MineFragmentManager.beginTransaction()
                                .replace(R.id.fl_contaciner,new MineFragment())
                                .commit();
                        break;
                }
            }
        });
    }

    private void initView() {
        mRGNavi = findViewById(R.id.rg_navi);
    }
}